﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DTO.Models.SURVEY>" %>
<% if (Model != null)
   { %>
<p>
    <%= Html.Encode(Model.Question) %></p>
<table>
    <% if (Model.Answer1.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="1" checked="checked" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer1)%></span>
        </td>
    </tr>
    <% } %>
    <% if (Model.Answer2.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="2" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer2)%></span>
        </td>
    </tr>
    <% } %>
    <% if (Model.Answer3.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="3" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer3)%></span>
        </td>
    </tr>
    <% } %>
    <% if (Model.Answer4.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="4" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer4)%></span>
        </td>
    </tr>
    <% } %>
    <% if (Model.Answer5.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="5" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer5)%></span>
        </td>
    </tr>
    <% } %>
    <% if (Model.Answer6.Length != 0)
       {%>
    <tr>
        <td width="5%">
            <input type="radio" name="radio" value="6" />
        </td>
        <td width="95%">
            <span>
                <%= Html.Encode(Model.Answer6)%></span>
        </td>
    </tr>
    <% } %>
    <tr>
        <td colspan="2" class="dung-text-center">
            <a class="dung-button-other" onclick="postSurvey()">Đồng ý</a>
            <a id="showResult" href='<%= Url.Content("~/Khaosat/KetQuaKhaoSat") %>' class="dung-button-other" target="_blank" onclick="resultSurvey()">Xem kết quả</a>
        </td>
    </tr>
</table>
<% } %>

<script type="text/javascript">

    function postSurvey() {
        var listid = "";
        $("input:checked").each(function () {
            listid += $(this).val();
        });
        if(listid.length == 0){
            confirm("Vui lòng chọn một lựa chọn");
        }
        else
        {
            if(confirm("Bạn đồng ý với lựa chọn?") == true)
            {
                $.post("/Khaosat/KhaoSatTop/" + listid + "?email=" + $("#email").val(),
                    function (data) {
                        if (parseInt(data, 0) == 1) {
                            alert("Đã lưu, mời bạn xem kết quả!");
                            $("#email").val("");
                        }
                        else {
                            if (parseInt(data, 0) == 2) {
                                alert("Bạn đã từng vote rồi, không thể vote nữa!");
                            }
                            else {
                                //if (parseInt(data, 0) == -1) {
                                //    alert("Email không chính xác!");
                                //}
                                //else {
                                    alert("Lưu không thành công!");
                                //}
                            }
                        }
                    });
            }
        }
    }
</script>
